# encoding: utf-8
from suit.apps import DjangoSuitConfig
from suit.menu import ParentItem, ChildItem


class SuitConfig(DjangoSuitConfig):
    layout = 'vertical'
    menu = (
        ParentItem(u'主机管理', children=[
            ChildItem(model='core.host'),
            ChildItem(model='core.trafficlog'),
            ChildItem(model='core.trafficchart'),
        ]),
        ParentItem(u'权限管理', permissions='core.view_staff', children=[
            ChildItem(model='core.staff'),
            ChildItem(model='core.department'),
        ]),
        # ParentItem(u'账号', children=[
        #     ChildItem(u'用户', model='auth.user'),
        #     ChildItem(u'部门', 'auth.group'),
        #     ChildItem(u'定制', url='/admin/custom/'),
        # ]),
        # ParentItem(u'右侧菜单', children=[
        #     ChildItem(u'修改密码', url='admin:password_change'),
        #     ChildItem(u'主页', url='http://yjidc.com', target_blank=True),
        # ], align_right=True),
    )

    def ready(self):
        super(SuitConfig, self).ready()

        # DO NOT COPY FOLLOWING LINE
        # It is only to prevent updating last_login in DB for demo app
        self.prevent_user_last_login()

    def prevent_user_last_login(self):
        """
        Disconnect last login signal
        """
        from django.contrib.auth import user_logged_in
        from django.contrib.auth.models import update_last_login
        user_logged_in.disconnect(update_last_login)
